package com.mingshashan.building.easy.core.exception;

import org.springframework.http.HttpStatus;

/**
 *
 */
public interface ErrorCoded {

    String getCode();

    String getErrorName();

    default int getStatus() {
        return 400;
    }

    default EasyRuntimeException exception(Object... params) {
        EasyErrorObject easyErrorObject = EasyErrorCodeTranslator.DEFAULT.translate(this, params);
        return new EasyRuntimeException(easyErrorObject);
    }

    default EasyRuntimeException exception(HttpStatus status, Object... params) {
        EasyErrorObject easyErrorObject = EasyErrorCodeTranslator.DEFAULT.translate(this, params);
        easyErrorObject.setStatus(status.value());
        return new EasyRuntimeException(EasyErrorCodeTranslator.DEFAULT.translate(this, params));
    }

    default EasyRuntimeException exception(Throwable cause, Object... params) {
        EasyErrorObject easyErrorObject = EasyErrorCodeTranslator.DEFAULT.translate(this, params);
        return new EasyRuntimeException(EasyErrorCodeTranslator.DEFAULT.translate(this, params), cause);
    }

    default EasyRuntimeException exception(HttpStatus status, Throwable cause, Object... params) {
        EasyErrorObject easyErrorObject = EasyErrorCodeTranslator.DEFAULT.translate(this, params);
        easyErrorObject.setStatus(status.value());
        return new EasyRuntimeException(EasyErrorCodeTranslator.DEFAULT.translate(this, params), cause);
    }

}
